package com.learn.test

import android.content.Context
import com.learn.test.unittest.ClassUnderTest
import com.learn.test.unittest.EmailValidator
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */

private const val FAKE_STRING = "HELLO WORLD"

@RunWith(MockitoJUnitRunner::class)
class ExampleUnitTest {
    @Mock
    private lateinit var mockContext: Context

    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun emailValidator_CorrectEmailSimple_RetrunsTrue() {
        assertTrue(EmailValidator.isValidEmail("test@qq.com"))
    }

    @Test
    fun readStringFromContext_LocalizedString() {
        val mockContext = mock<Context>() {
            on { getString(R.string.app_name) } doReturn FAKE_STRING
        }

        val myObjectUnderTest = ClassUnderTest(mockContext)
        val result = myObjectUnderTest.getName()
        assertEquals(result, FAKE_STRING)
    }
}